import { getFeedbackBySId,addFeedback } from "../../api/manage";

Page({
  data: {
    records: [],
    showPanel:false,
    animationData: {translateY: '100%'},
    selectedFeedbackType: '教学', // 选中的反馈类型
    feedbackContent: '', // 反馈内容
  },

  onLoad: function() {
    // 页面加载时执行的操作
    const userID = wx.getStorageSync('userID');
    getFeedbackBySId(userID).then((res) => {
      const processedData = res.data.map(item => {
        return {
          ...item,
          type: `${item.feedbackType}`,
          content:`${item.content}`,
          progress:`${item.result}`,
          reply:`${item.response==null?'无':item.response}`
        };
      });
      // 将处理后的数据设置到页面的data中
      this.setData({ records: processedData });
    });
  },

  showSlidePanel: function() {
    const animationData = {
      translateY: '0%'
    };
    this.setData({
      animationData: animationData,
      showPanel: true
    });
  },
  hidePanel: function() {
    const animationData = {
      translateY: '100%'
    };
    this.setData({
      animationData: animationData,
    });
    setTimeout(() => {
      this.setData({
        showPanel: false
      });
    }, 300); // 确保动画完成后再隐藏面板
  },

  selectFeedbackType: function(e) {
    this.setData({ selectedFeedbackType: e.currentTarget.dataset.type });
  },

  inputContent: function(e) {
    this.setData({ feedbackContent: e.detail.value });
   },

  submitFeedback: function() {
    // 提交反馈逻辑
    addFeedback(wx.getStorageSync('userID'), 
                this.data.feedbackContent, 
                this.data.selectedFeedbackType).then(res=>{
                  wx.showToast({
                    title: res.msg,
                    icon:'none'
                  });
                  this.onLoad(); // 提交后刷新页面
                });
    this.hidePanel(); // 提交后隐藏子页面
  }
});